<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="common/commonInclude.jsp"%>
<link rel="stylesheet" href="<%=basePath %>AmazeUI-2.1.0/assets/css/amazeui.min.css"/>
<link rel="stylesheet" href="<%=basePath %>AmazeUI-2.1.0/assets/css/admin.css">
<script type="text/javascript" src="<%=basePath %>assets/js/jquery-1.11.1.js"></script>

<script type="text/javascript">
function reload(){
	$.ajax({
		url : 'list',
		dataType : 'json',
		success : function (data) {
			if (data.ret == 0) {
				
				data = data.data;
				$('table tbody').empty();
				for(var i=0;i<data.length ;i++) {
					var d = data[i];
					var str = '<tr><td>'+d.id+'</td><td>'
					+d.name+'</td><td>'+d.cid+'</td><td>'+d.secret+'</td><td>'
					+d.username+'</td><td>'
					+'<button class="am-btn am-btn-warning am-round" onclick="resetPassword('+d.id+')">重置密码</button>'
					+'<button class="am-btn am-btn-danger am-round" onclick="deleteClient('+d.id+')">删除</button></td></tr>'
					$('table tbody').append(str);
				}
			} else {
				alert('加载数据异常');
			}
		}
	})
	
}
function resetPassword(id){
	if (window.confirm('重置密码？')) {
		$.ajax({
			url : 'resetPassword',
			data : {id : id},
			dataType : 'json',
			success : function (data) {
				if (data.ret == 0) {
					alert("新密码：" + data.data);
				} else {
					alert(data.data);
				}
			}
		})
	}
}
function deleteClient(id){
	if (window.confirm('确定删除客户端？')) {
		$.ajax({
			url : 'delete',
			data : {id : id},
			dataType : 'json',
			success : function (data) {
				reload();
				if (data.ret != 0) {
					alert(data.data);
				}
			}
		})
	}
}
$(function(){
	reload();
})
</script>
</head>
<body>
<table class="am-table am-table-bordered am-table-striped am-table-hover">
	<thead>
		<tr>
			<th>ID</th>
			<th>名称</th>
			<th>appid</th>
			<th>secret</th>
			<th>账号</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody>
	
	</tbody>
</table>
</body>
</html>